#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution {
public:
    bool isMonotonic(vector<int>& A) {
        int status = -1; //用于记录前一个状态
        if(A.size()==1){
            return true;
        }
        for(int i = 0;i<A.size()-1;++i){
            if(i == 0){
                if(A[i]<A[i+1]){
                    status = 0;
                }
                else if(A[i]>A[i+1]){
                    status = 1;
                }
                else{
                    status = 2;
                }
            }
            else{
               if(status==0&&A[i]>A[i+1]){
                   return false;
               }
               else if(status==1&&A[i]<A[i+1]){
                   return false;
               }
               else if(status==2){
                   if(A[i]<A[i+1]){
                       status =0;
                   }
                   else if(A[i]>A[i+1]){
                       status =1;
                   }
                   else{
                       status =2;
                   }
               }
            }
        }
        return true;
    }
};